!测试通信域信息.按奇偶分裂通信域
!mpifort mpi_comm_split.F90 -o mpi_comm_split
!mpirun -np 4 -x LD_PRELOAD=/home/luosf321/tool_chain/build/libs/mpitracer/libmpitracer.so mpi_comm_split

program mpi_comm_split_demo
        use mpi
        implicit none
        integer :: ierr, rank, size, color, new_rank, new_size
        integer :: world_comm, new_comm
        integer :: odd_even_key

        call MPI_Init(ierr)
        call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
        call MPI_Comm_size(MPI_COMM_WORLD, size, ierr)

        print '(A, I0, A, I0)', 'Process ', rank, '/', size - 1, 'in MPI_COMM_WORLD'

        color = mod(rank, 2)
        odd_even_key = rank

        call MPI_Comm_split(MPI_COMM_WORLD, color, odd_even_key, new_comm, ierr)

        call MPI_Comm_rank(new_comm, new_rank, ierr)
        call MPI_Comm_size(new_comm, new_size, ierr)
        print '(A, I0, A, I0, A, I0, A, I0)', 'Process ', rank, ' -> NewComm ', new_rank, '/', new_size - 1, ' (Color:  ', color, ')'

        call MPI_Comm_free(new_comm, ierr)
        call MPI_FINALIZE(ierr)

end program mpi_comm_split_demo
